package com.fenxiangle.yueding.feature.focus.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.fenxiangle.yueding.R;
import com.fenxiangle.yueding.entity.bo.AliPayBo;
import com.fenxiangle.yueding.entity.bo.MyAccountBo;
import com.fenxiangle.yueding.entity.bo.TranscctionBo;
import com.fenxiangle.yueding.feature.home.view.adapter.ExpandableItemAdapter;
import com.fenxiangle.yueding.feature.home.view.adapter.ExpandableYJAdapter;
import com.fenxiangle.yueding.feature.mine.view.MyCreditActivity;
import com.fenxiangle.yueding.feature.mine.view.MyServiceActivity;
import com.fenxiangle.yueding.feature.publish.contract.PayContract;
import com.fenxiangle.yueding.feature.publish.dependencies.pay.DaggerPayComponent;
import com.fenxiangle.yueding.feature.publish.dependencies.pay.PayPresenterModule;
import com.fenxiangle.yueding.framework.api.UserApi;
import com.suozhang.framework.component.http.RxDataProcessFactory;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Home on 2018/9/1.
 */

public class AccountDetailsActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.wallet_recyclerView)
    RecyclerView walletRecyclerView;
    ExpandableYJAdapter adapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_wallet_detail;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        initToolBar(toolbar, "明细", true, true);
        walletRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    protected void initData() {

        AM.api().createApiService(UserApi.class)
                .getCommissionDetails()
                .compose(RxDataProcessFactory.dataPrepAndIoToMainTransformer())
                .subscribe(new Observer<List<TranscctionBo>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        showLoading(d);
                    }

                    @Override
                    public void onNext(List<TranscctionBo> walletFirstBos) {
                        dismissLoading();
                        if (walletFirstBos!=null&&walletFirstBos.size()>0){
                            ArrayList<MultiItemEntity> res = new ArrayList<>();

                            if (walletFirstBos != null && !walletFirstBos.isEmpty()) {
                                for (int i = 0; i < walletFirstBos.size(); i++) {
                                    TranscctionBo lv0 = walletFirstBos.get(i);
                                    for (int j = 0; j < lv0.getCommissionFormMap().size(); j++) {
                                        TranscctionBo.CommissionFormMapBean lv1 = lv0.getCommissionFormMap().get(j);
                                        lv0.addSubItem(lv1);
                                    }
                                    res.add(lv0);
                                }
                            }

                            adapter = new ExpandableYJAdapter(res);
                            walletRecyclerView.setAdapter(adapter);
                            adapter.expandAll();
                        }else {

                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        dismissLoading();
                    }

                    @Override
                    public void onComplete() {
                        dismissLoading();
                    }
                });

    }
}